pub use self::source::{
Source,
SourceId,
+ SourceMap,
SourceSet,
GitKind,
PathKind,
+use std::collections::HashMap;
use std::vec::Vec;
-use core::{Source, SourceId, Summary, Dependency, PackageId, Package};
+use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package};
use util::{CargoResult, ChainError, Config, human};
pub trait Registry {
}
pub struct PackageRegistry<'a> {
- sources: Vec<Box<Source>>,
+ sources: SourceMap,
overrides: Vec<Summary>,
summaries: Vec<Summary>,
- searched: Vec<SourceId>,
config: &'a mut Config<'a>
}
fn empty<'a>(config: &'a mut Config<'a>) -> PackageRegistry<'a> {
PackageRegistry {
- sources: vec!(),
+ sources: SourceMap::new(),
overrides: vec!(),
summaries: vec!(),
- searched: vec!(),
config: config
}
}
// source
let mut ret = Vec::new();
- for source in self.sources.iter() {
+ for source in self.sources.sources() {
try!(source.download(package_ids));
let packages = try!(source.get(package_ids));
Ok(ret)
}
+ pub fn move_sources(self) -> SourceMap {
+ self.sources
+ }
+
fn ensure_loaded(&mut self, namespace: &SourceId) -> CargoResult<()> {
- if self.searched.contains(namespace) { return Ok(()); }
+ if self.sources.contains(namespace) {
+ return Ok(());
+ }
+
try!(self.load(namespace, false));
Ok(())
}
fn load(&mut self, namespace: &SourceId, override: bool) -> CargoResult<()> {
-
(|| {
let mut source = namespace.load(self.config);
let dst = if override {&mut self.overrides} else {&mut self.summaries};
}
// Save off the source
- self.sources.push(source);
-
- // Track that the source has been searched
- self.searched.push(namespace.clone());
+ self.sources.insert(namespace, source);
Ok(())
}).chain_error(|| human(format!("Unable to update {}", namespace)))
use std::collections::HashMap;
+use std::fmt;
+use serialize::{Encodable, Encoder};
use util::graph::{Nodes,Edges};
use core::{
}
}
+impl fmt::Show for Resolve {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ self.graph.fmt(fmt)
+ }
+}
+
struct Context<'a, R> {
registry: &'a mut R,
resolve: Resolve,
let mut context = Context::new(registry);
try!(resolve_deps(root, deps, &mut context));
+ log!(5, " result={}", context.resolve);
Ok(context.resolve)
}
+use std::collections::HashMap;
+use std::collections::hashmap::Values;
use std::fmt;
use std::fmt::{Show, Formatter};
use std::hash;
}
pub fn load(&self, config: &mut Config) -> Box<Source> {
+ log!(5, "loading SourceId; {}", self);
match self.kind {
GitKind(..) => box GitSource::new(self, config) as Box<Source>,
PathKind => {
}
}
+pub struct SourceMap {
+ map: HashMap<SourceId, Box<Source>>
+}
+
+pub type Sources<'a> = Values<'a, SourceId, Box<Source>>;
+
+impl SourceMap {
+ pub fn new() -> SourceMap {
+ SourceMap {
+ map: HashMap::new()
+ }
+ }
+
+ pub fn contains(&self, id: &SourceId) -> bool {
+ self.map.contains_key(id)
+ }
+
+ pub fn get(&self, id: &SourceId) -> Option<&Source> {
+ let source = self.map.find(id);
+
+ source.map(|s| {
+ let s: &Source = *s;
+ s
+ })
+ }
+
+ pub fn get_by_package_id(&self, pkg_id: &PackageId) -> Option<&Source> {
+ self.get(pkg_id.get_source_id())
+ }
+
+ pub fn insert(&mut self, id: &SourceId, source: Box<Source>) {
+ self.map.insert(id.clone(), source);
+ }
+
+ pub fn len(&self) -> uint {
+ self.map.len()
+ }
+
+ pub fn sources(&self) -> Sources {
+ self.map.values()
+ }
+}
+
pub struct SourceSet {
sources: Vec<Box<Source>>
}
manifest_path.dir_path()));
let source_ids = package.get_source_ids();
- let (packages, resolve) = {
+ let (packages, resolve, sources) = {
let mut config = try!(Config::new(*shell, update, jobs, target.clone()));
let mut registry =
human("Unable to get packages from source")
}));
- (packages, resolved)
+ (packages, resolved, registry.move_sources())
};
debug!("packages={}", packages);
try!(scrape_target_config(&mut config, &user_configs));
try!(ops::compile_targets(env.as_slice(), targets.as_slice(), &package,
- &PackageSet::new(packages.as_slice()), &resolve, &mut config));
+ &PackageSet::new(packages.as_slice()), &resolve, &sources, &mut config));
let test_executables: Vec<String> = targets.iter()
.filter_map(|target| {
use std::os;
use std::str;
-use core::{Package, PackageId, PackageSet, Resolve, Target};
+use core::{SourceMap, Package, PackageId, PackageSet, Resolve, Target};
use util;
use util::{CargoResult, ChainError, internal, Config};
pub rustc_version: String,
pub config: &'b mut Config<'b>,
pub resolve: &'a Resolve,
+ pub sources: &'a SourceMap,
env: &'a str,
host: Layout,
}
impl<'a, 'b> Context<'a, 'b> {
- pub fn new(env: &'a str, resolve: &'a Resolve, deps: &'a PackageSet,
- config: &'b mut Config<'b>,
+ pub fn new(env: &'a str, resolve: &'a Resolve, sources: &'a SourceMap,
+ deps: &'a PackageSet, config: &'b mut Config<'b>,
host: Layout, target: Option<Layout>)
-> CargoResult<Context<'a, 'b>> {
let (target_dylib, target_exe) =
target: target,
primary: false,
resolve: resolve,
+ sources: sources,
package_set: deps,
config: config,
target_dylib: target_dylib,
fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target])
-> CargoResult<(bool, String)> {
- let dep_fingerprint = try!(get_fingerprint(dep, cx.config));
+ let dep_fingerprint = try!(get_fingerprint(dep, cx));
let new_pkg_fingerprint = format!("{}{}", cx.rustc_version, dep_fingerprint);
let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets));
Ok((old_fingerprint == new_fingerprint, new_fingerprint))
}
+fn get_fingerprint(pkg: &Package, cx: &Context) -> CargoResult<String> {
+ let source = cx.sources
+ .get(pkg.get_package_id().get_source_id())
+ .expect("BUG: Missing package source");
+
+ source.fingerprint(pkg)
+}
+
fn hash_targets(targets: &[&Target]) -> u64 {
let hasher = SipHasher::new_with_keys(0,0);
let targets = targets.iter().map(|t| (*t).clone()).collect::<Vec<Target>>();
let hasher = SipHasher::new_with_keys(0,0);
util::to_hex(hasher.hash(&(package, profiles)))
}
-
-fn get_fingerprint(pkg: &Package, config: &mut Config) -> CargoResult<String> {
- let source_id = pkg.get_package_id().get_source_id();
- let source = source_id.load(config);
- source.fingerprint(pkg)
-}
use std::os;
use semver::Version;
-use core::{Package, PackageId, PackageSet, Target, Resolve};
+use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve};
use util;
use util::{CargoResult, ProcessBuilder, CargoError, human, caused_human};
use util::{Config, Freshness, internal, ChainError};
}
pub fn compile_targets<'a>(env: &str, targets: &[&'a Target], pkg: &'a Package,
- deps: &PackageSet, resolve: &'a Resolve,
+ deps: &PackageSet, resolve: &'a Resolve, sources: &'a SourceMap,
config: &'a mut Config<'a>) -> CargoResult<()> {
if targets.is_empty() {
return Ok(());
layout::Layout::new(root.join(target).join(dest))
});
- let mut cx = try!(Context::new(env, resolve, deps, config,
+ let mut cx = try!(Context::new(env, resolve, sources, deps, config,
host_layout, target_layout));
// First ensure that the destination directory exists
use core::{Package, PackageId, Summary, SourceId, Source};
use ops;
-use util::{CargoResult, internal};
+use util::{CargoResult, internal, internal_error};
pub struct PathSource {
id: SourceId,
impl PathSource {
pub fn for_path(path: &Path) -> PathSource {
+ log!(5, "PathSource::for_path; path={}", path.display());
PathSource::new(path, &SourceId::for_path(path))
}
}
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
- let packages = try!(self.read_packages());
+ if !self.updated {
+ return Err(internal_error("BUG: source was not updated", ""));
+ }
+
let mut max = 0;
- for pkg in packages.iter().filter(|p| *p == pkg) {
+
+ for pkg in self.packages.iter().filter(|p| *p == pkg) {
let loc = pkg.get_manifest_path().dir_path();
max = cmp::max(max, try!(walk(&loc, true)));
}
+
return Ok(max.to_string());
fn walk(path: &Path, is_root: bool) -> CargoResult<u64> {
+use std::fmt;
use std::hash::Hash;
use std::collections::{HashMap, HashSet};
use std::collections::hashmap::{Keys, SetItems};
self.nodes.keys()
}
}
+
+impl<N: fmt::Show + Eq + Hash> fmt::Show for Graph<N> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ try!(writeln!(fmt, "Graph {{"));
+
+ for (n, e) in self.nodes.iter() {
+ try!(writeln!(fmt, " - {}", n));
+
+ for n in e.iter() {
+ try!(writeln!(fmt, " - {}", n));
+ }
+ }
+
+ try!(write!(fmt, "}}"));
+
+ Ok(())
+ }
+}